<template>
  <div>
    <h1>欢迎:{{userName}}</h1>
    <button @click="add">添加操作 权限1</button>
    <button @click="edit">修改操作 权限2</button>
    <button @click="query">查询操作 无权限</button>
    <button @click='quite'>退出系统</button>
  </div>
</template>

<script>
export default {

  name: 'WelcomeView',

  data () {
    return {
      userName:''
    }
  },
  created(){
    this.userName = window.sessionStorage.getItem('userName')
  },
  methods: {
    add () {
      this.axios({
        method:'post',
        url:'/api/add'
      }).then(rs => {
        console.log(rs.data)
        alert(rs.data.msg)
      })
    },
    edit () {
      this.axios({
        method:'post',
        url:'/api/edit'
      }).then(rs=>{
        alert(rs.data.msg)
      })
    },
    query () {
      this.axios({
        method:'get',
        url:'/api/query'
      }).then(rs=>{
        alert(rs.data.msg)
      })
    },
    quite () {
      this.axios({
        url:'/api/exit'
      }).then(rs=>{
        console.log("exit",rs.data)
        if(rs.data.code === 200){
          console.log('========')
          window.sessionStorage.clear()
          this.$router.push("/")
        }
      })
    }
  }
}
</script>

<style lang="css" scoped>
</style>